package momo.multitree.algo;

import momo.multitree.structure.*;

import java.io.FileReader;
import java.util.LinkedHashSet;

import junit.framework.TestCase;


public class LatencyShortestPathTest extends TestCase
{

	public void testOneOptimumTree()
	{
		Node node1 = new Node("1", 0.3, 1);
		Node node2 = new Node("2", 0.2, 1);
		Node node3 = new Node("3", 0.1, 1);
		Node node4 = new Node("4", 0.1, 1);
		Node node5 = new Node("5", 0.2, 1);
		Node node6 = new Node("6", 0.1, 1);
		
		Edge edge1 = new Edge("1", node1, node2, 1, 1, 3, 3);
		Edge edge2 = new Edge("2", node1, node3, 1, 1, 2, 2);
		Edge edge3 = new Edge("3", node2, node3, 1, 1, 1, 1);
		Edge edge4 = new Edge("4", node2, node5, 1, 1, 2, 2);
		Edge edge5 = new Edge("5", node3, node5, 1, 1, 4, 4);
		Edge edge6 = new Edge("6", node3, node6, 1, 1, 6, 6);
		Edge edge7 = new Edge("7", node6, node5, 1, 1, 2, 2);
		Edge edge8 = new Edge("8", node4, node5, 1, 1, 1, 1);
		Edge edge9 = new Edge("9", node2, node4, 1, 1, 4, 4);
		
		Graph graph = new Graph();
		graph.add(edge1);
		graph.add(edge2);
		graph.add(edge3);
		graph.add(edge4);
		graph.add(edge5);
		graph.add(edge6);
		graph.add(edge7);
		graph.add(edge8);
		graph.add(edge9);
		
		LatencyShortestPath app = new LatencyShortestPath();
		Tree tree1 = app.optimumTree(graph, node1);
		
		Tree tree2 = new Tree(node1);
		tree2.add(edge2);
		tree2.add(edge1);
		tree2.add(edge4);
		tree2.add(edge8);
		tree2.add(edge7);
		
		assertTrue(tree2.compare(tree1));
	}
	
	public void testOptimumTree()
	{
		Node node1 = new Node("1", 0.3, 1);
		Node node2 = new Node("2", 0.2, 1);
		Node node3 = new Node("3", 0.1, 1);
		Node node4 = new Node("4", 0.1, 1);
		Node node5 = new Node("5", 0.2, 1);
		Node node6 = new Node("6", 0.1, 1);
		
		Edge edge1 = new Edge("1", node1, node2, 1, 1, 3, 3);
		Edge edge2 = new Edge("2", node1, node3, 1, 1, 2, 2);
		Edge edge3 = new Edge("3", node2, node3, 1, 1, 1, 1);
		Edge edge4 = new Edge("4", node2, node5, 1, 1, 2, 2);
		Edge edge5 = new Edge("5", node3, node5, 1, 1, 4, 4);
		Edge edge6 = new Edge("6", node3, node6, 1, 1, 6, 6);
		Edge edge7 = new Edge("7", node6, node5, 1, 1, 2, 2);
		Edge edge8 = new Edge("8", node4, node5, 1, 1, 1, 1);
		Edge edge9 = new Edge("9", node2, node4, 1, 1, 4, 4);
		
		Graph graph = new Graph();
		graph.add(edge1);
		graph.add(edge2);
		graph.add(edge3);
		graph.add(edge4);
		graph.add(edge5);
		graph.add(edge6);
		graph.add(edge7);
		graph.add(edge8);
		graph.add(edge9);
		
		LatencyShortestPath app = new LatencyShortestPath();

		Tree tree1 = app.optimumTree(graph, node1);
		Tree tree2 = app.optimumTree(graph, node2);
		Tree tree3 = app.optimumTree(graph, node3);
		Tree tree4 = app.optimumTree(graph, node4);
		Tree tree5 = app.optimumTree(graph, node5);
		Tree tree6 = app.optimumTree(graph, node6);
		
		assertTrue(tree2.compare(app.optimumTree(graph)));
	}
}//end of LatencyShortestPathTest
